home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / gfx / edit / TSMrph23s.lha / TSM23s.lha / LoadBrushes.c < prev    next >
C/C++ Source or Header  |  1993-10-08  |  5KB  |  176 lines

  1. // TSMorph - Amiga Morphing program
  2. // Copyright (C) © 1993  Topicsave Limited
  3.  
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; either version 2 of the License, or
  7. // any later version.
  8.  
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. // GNU General Public License for more details.
  13.  
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program; if not, write to the Free Software
  16. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. // mpaddock@cix.compulink.co.uk
  19.  
  20. //    $Author: M_J_Paddock $
  21. //    $Date: 1992/08/08 01:06:24 $
  22. //    $Revision: 1.4 $
  23.  
  24. // include precompiled header if not already
  25. #ifndef TSMOPRH_H
  26. #include "TSMorph.h"
  27. #endif
  28.  
  29. /* version of loadbrush which first check file exists
  30.  * to prevent any error message being displayed if not present
  31.  */
  32. int
  33. myloadbrush(struct ILBMInfo *info,UBYTE *filename) {
  34.     BPTR fh;
  35.     if (fh = Open(filename,MODE_OLDFILE)) {
  36.         Close(fh);
  37.         return loadbrush(info,filename);
  38.     }
  39.     return 1;
  40. }
  41.  
  42. /* load a pointer from a 4 colour ILBM file.
  43.  *
  44.  * ilbm     - ILBM stuff
  45.  * address  - address to store sprite
  46.  * filename - name of iff file to load
  47.  */
  48. void
  49. mycopysprite(struct ILBMInfo *ilbm,UWORD __chip *address,UBYTE *filename) {
  50.     int i;
  51.     UWORD *p0,*p1,*o0;
  52.     // try and load brush first
  53.     if (!myloadbrush(ilbm,filename)) {
  54.         // if ok then convert to pointer format
  55.         p0 = (UWORD *)ilbm->brbitmap->Planes[0];
  56.         p1 = (UWORD *)ilbm->brbitmap->Planes[1];
  57.         o0 = address + 2;
  58.         for (i = 0;
  59.               i < 32;
  60.               ++i) {
  61.             *o0++ = *p0++;
  62.             *o0++ = *p1++;
  63.         }
  64.     }
  65.     // close and unload brush
  66.     closeifile(&(ilbm->ParseInfo));
  67.     unloadbrush(ilbm);
  68. }
  69.  
  70. /* load an image from a 4 colour ILBM file
  71.  *
  72.  * ilbm     - ILBM stuff
  73.  * im       - pointer to image to store data
  74.  * filename - name of iff file to load
  75.  * size     - size of image bit plane
  76.  */
  77. void
  78. mycopybrush(struct ILBMInfo *ilbm,struct Image *im,UBYTE *filename,UWORD size) {
  79.     // try and load brush first
  80.     if (!myloadbrush(ilbm,filename)) {
  81.         // if ok then copy to image data
  82.         CopyMem(im->ImageData,ilbm->brbitmap->Planes[0],size);
  83.         CopyMem(((UBYTE *)im->ImageData)+size,ilbm->brbitmap->Planes[1],size);
  84.     }
  85.     // close and unload brush
  86.     closeifile(&(ilbm->ParseInfo));
  87.     unloadbrush(ilbm);
  88. }
  89.  
  90. /* Invert an image for a highlighted gadget
  91.  * this is used rather than complement to look good on >4 colour screen
  92.  * (There must be a better way)
  93.  *
  94.  * im    - Image pointer, note that the memory for the image data is twice the required size
  95.  * size  - size of image data
  96.  */
  97. void
  98. invertbrush(struct Image *im,UWORD size) {
  99.     UWORD *a,*b;
  100.     UWORD i;
  101.     a = im->ImageData,
  102.     b = im->ImageData+size;
  103.     for (i = 0;
  104.           i < size;
  105.           i++) {
  106.         *b++ = ~*a++;
  107.     }
  108. }
  109.  
  110. /* Load pointer and
  111.  * gadget images
  112.  */
  113. void
  114. LoadBrushes(void) {
  115.     struct ILBMInfo    ilbm = {0};        // ILBM info for iff read
  116.     BPTR                     lock, cd;        // lock on new directory and old directory
  117.     if (ilbm.ParseInfo.iff = AllocIFF()) {    // get IFF stuff
  118.         ilbm.ParseInfo.propchks = props;        // and initialise chunks required
  119.         ilbm.ParseInfo.collectchks = nowt;
  120.         ilbm.ParseInfo.stopchks = stops;
  121.         if (lock = Lock("TSMorph:brush",ACCESS_READ)) {    // try and change to this directory
  122.             cd = CurrentDir(lock);
  123.             // Load all image files
  124.             mycopybrush(&ilbm,&Add_im,"add",204);
  125.             mycopybrush(&ilbm,&Del_im,"del",204);
  126.             mycopybrush(&ilbm,&Link_im,"link",204);
  127.             mycopybrush(&ilbm,&None_im,"none",204);
  128.             mycopybrush(&ilbm,&One_im,"one",204);
  129.             mycopybrush(&ilbm,&Rel_im,"rel",204);
  130.             mycopybrush(&ilbm,&Two_im,"two",204);
  131.             mycopybrush(&ilbm,&Unlink_im,"unlink",204);
  132.             mycopybrush(&ilbm,&st_im,"1st",30);
  133.             mycopybrush(&ilbm,&prev_im,"prev",30);
  134.             mycopybrush(&ilbm,&goto_im,"goto",30);
  135.             mycopybrush(&ilbm,&next_im,"next",30);
  136.             mycopybrush(&ilbm,&last_im,"last",30);
  137.             // switch back to old dir
  138.             CurrentDir(cd);
  139.             UnLock(lock);
  140.         }
  141.         // invert all gadgets for hilite
  142.         invertbrush(&Add_im,204);
  143.         invertbrush(&Del_im,204);
  144.         invertbrush(&Link_im,204);
  145.         invertbrush(&None_im,204);
  146.         invertbrush(&One_im,204);
  147.         invertbrush(&Rel_im,204);
  148.         invertbrush(&Two_im,204);
  149.         invertbrush(&Unlink_im,204);
  150.         invertbrush(&st_im,30);
  151.         invertbrush(&prev_im,30);
  152.         invertbrush(&goto_im,30);
  153.         invertbrush(&next_im,30);
  154.         invertbrush(&last_im,30);
  155.         if (lock = Lock("TSMorph:cursor",ACCESS_READ)) {    // try and change to this directory
  156.             cd = CurrentDir(lock);
  157.             // Load all pointer files
  158.             mycopysprite(&ilbm,Add,"XAdd");
  159.             mycopysprite(&ilbm,Del,"XDel");
  160.             mycopysprite(&ilbm,L1,"XL1");
  161.             mycopysprite(&ilbm,L2,"XL2");
  162.             mycopysprite(&ilbm,Mov,"XMov");
  163.             mycopysprite(&ilbm,One,"XOne");
  164.             mycopysprite(&ilbm,Rel,"XRel");
  165.             mycopysprite(&ilbm,Two,"XTwo");
  166.             mycopysprite(&ilbm,U1,"XU1");
  167.             mycopysprite(&ilbm,U2,"XU2");
  168.             // switch back to old dir
  169.             CurrentDir(cd);
  170.             UnLock(lock);
  171.         }
  172.         // free IFF stuff
  173.         FreeIFF(ilbm.ParseInfo.iff);
  174.     }
  175. }    
  176.